package service;

import UI.Clientcontext;
import UI.ExamFrame;
import beans.Datebase;

public class Controller {
	private Clientcontext client;
	private Datebase db = new Datebase();
	private int i = 0;
	private int m;
	private String answer;

	public boolean login(String id, String password) {
		boolean flag = false;
		for (int i = 0; i < db.getList().size(); i++) {
			if (id.equals(db.getList().get(i).getId()) && password.equals(db.getList().get(i).getPassword())) {
				return flag = true;
			}
		}
		return flag;
	}

	public String loginname(String id) {
		String name = null;
		for (int i = 0; i < db.getList().size(); i++) {
			if (id.equals(db.getList().get(i).getId())) {
				String n;
				n = db.getList().get(i).getName();
				name = n;
			}
		}
		return name;
	}

	public String start() {
		m = (int) (Math.random() * 10);
		db.getpaper();
		return db.getPaper().get(m).getPaper().get(i).toString();
	}

	public String next() {
		String next = null;
		i++;
		if (i != 20) {
			return db.getPaper().get(m).getPaper().get(i).toString();
		}
		return next;
	}

	public String last() {
		i--;

		return db.getPaper().get(m).getPaper().get(i).toString();
	}

	public int getM() {
		return m;
	}

	public void setI(int i) {
		this.i = i;
	}

	public int getI() {
		return i;
	}

	public Datebase getDb() {
		return db;
	}

	public void setClient(Clientcontext client) {
		this.client = client;
	}

}
